package com.wanshi.test;

import java.lang.reflect.Method;

public class DD extends Thread {

    private Object result;

    public Object getResult() {
        return result;
    }

    @Override
    public void run() {
        try {
            System.out.println("-------子线程开始-----------");
            Class<?> c = Class.forName("com.wanshi.test.CC");
            // 反射类的方法：
            Method[] ms = c.getMethods();
            for (int i = 0; i < ms.length; i++) {
                String methodName = ms[i].getName();
                if (methodName.equals("add")) {
                    Object t = ms[i].invoke(c.getDeclaredConstructor().newInstance(), 2, 3);
                    result = t;
                    System.out.println("-------子线程结束-----------");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("抛异常了------");
        }
    }
}
